package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Enquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.EnquiryQuery;
import com.by.query.SaleEnquiryQuery;
import com.by.service.EnquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags ="客户询价" )
@RequestMapping("/v1")
public class EnquiryController extends BaseController {
    @Autowired
    EnquiryService enquiryService;


    @ApiOperation("保存询价单")
    @PostMapping("/enquiry")
    public ResultBean save(@RequestBody Enquiry enquiry){
        int rs=enquiryService.save(enquiry);
        return saveResult(rs);
    }


    @ApiOperation("查询询价单")
    @PostMapping("/enquiry/query")
    public ResultBean query(@RequestBody EnquiryQuery enquiryQuery){
        Map<String,Object> params= BeanUtil.beanToMap(enquiryQuery);
        PageBean res=enquiryService.query(params);
        return success("报价列表",res);
    }

    @ApiOperation("查询询价单")
    @PostMapping("/enquiry/list")
    public ResultBean queryEnquiry(@RequestBody SaleEnquiryQuery saleEnquiryQuery){
        PageBean res=enquiryService.queryEnquiry(saleEnquiryQuery);
        return success("询价列表",res);
    }
}
